package com.hnevc.trafficexpanedlistviewdemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2017/12/14.
 */

public class ExpendableListViewAdapter extends BaseExpandableListAdapter {
    List<List<BusInfo>> mBusInfoListList;
    List<String> mStationNamesList;
    Context mContext;

    public ExpendableListViewAdapter(List<List<BusInfo>> infos,List<String> stationNamesList, Context context) {
        mBusInfoListList = infos;
        mStationNamesList = stationNamesList;
        mContext = context;
    }

    @Override
    public int getGroupCount() {
        return mStationNamesList.size();
    }

    @Override
    public int getChildrenCount(int i) {
        List<BusInfo> busInfoList =mBusInfoListList.get(i);
        return busInfoList.size();
    }

    @Override
    public Object getGroup(int i) {
        return mStationNamesList.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        List<BusInfo> busInfoList = mBusInfoListList.get(i);
        return busInfoList.get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        View groupview = LayoutInflater.from(mContext).inflate(R.layout.parent_list_item,null);
        TextView textView = (TextView) groupview.findViewById(R.id.id_tv_parent);
        textView.setText(mStationNamesList.get(i));
        return groupview;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        View childView = LayoutInflater.from(mContext).inflate(R.layout.list_item,null);
        List<BusInfo> busInfoList = mBusInfoListList.get(i);

        BusInfo busInfo = busInfoList.get(i1);
        TextView mTvBusName = (TextView) childView.findViewById(R.id.id_busname);
        mTvBusName.setText(busInfo.getBusId()+"号");
        TextView mTvBusRenshu = (TextView) childView.findViewById(R.id.id_bus_renshu);
        mTvBusRenshu.setText("("+busInfo.getPersonNum()+"人）");
        TextView mTvDistance = (TextView) childView.findViewById(R.id.id_bus_arrivedistance);
        mTvDistance.setText("距离站台"+busInfo.getDistance()+"米");
        TextView mTvArriveTime = (TextView) childView.findViewById(R.id.id_bus_arrivetime);
        mTvArriveTime.setText(busInfo.getArriveTime()+"分钟到达");

        return childView;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }
}
